﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class BasePanel : MonoBehaviour
{
    [HideInInspector]
    public string panelName;
    [HideInInspector]
    public UIManager uiManager;
    [HideInInspector]
    public UIData uiData;
    public List<GameObject> uiElementObjList;
    protected UIElementHandle uiElementHandle;

    public void init()
    {
        uiElementHandle = new UIElementHandle(ref uiElementObjList, this);
        OnInit();
    }

    protected virtual void OnInit() {

    }

    public virtual void OnEnter()
    {
        Show();
    }
    public virtual void OnPause()
    {
        Hide();
    }
    public virtual void OnResume()
    {
        Show();
    }
    public virtual void OnExit() {
        Hide();
    }

    //显示面板
    public void Show() {
        gameObject.SetActive(true);
    }

    //隐藏面板
    public void Hide() {
        gameObject.SetActive(false);
    }

    //查找Button
    public ButtonUIElement FindButton(string buttonName) {
        return uiElementHandle.FindButton(buttonName);
    }

    //查找Text
    public TextUIElement FindText(string TextName)
    {
        return uiElementHandle.FindText(TextName);
    }

    //查找所有类型的UI元素
    public BaseUIElement FindUIElement(string buttonName, string type) {
        return uiElementHandle.FindUIElement(buttonName, type);
    }
}
